//
//  HEDoctorMainPageViewController.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/17.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEDoctorMainPageViewController.h"
#import "HEDoctorMainInfoCell.h"
#import "HEDoctorMainSkuffCell.h"

@interface HEDoctorMainPageViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) GDTableView *tableView;
@property (nonatomic, strong) NSMutableArray * dataSourceArr;
@property (nonatomic, strong) NSArray *titleArr;
@property (nonatomic, strong) NSArray *titleIcon;
@property (nonatomic, strong) HEDoctorInfoModel *details;

@end

@implementation HEDoctorMainPageViewController

- (NSMutableArray *)dataSourceArr {
    if (!_dataSourceArr) {
        _dataSourceArr = [NSMutableArray array];
    }
    return _dataSourceArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"医生主页";
    
    
    [self loadMainData];
}

- (void)loadMainData {
 
    [WOAFNetWorkingHandle POSTWithBaseUrl:KServerUrl suffixUrl:KdoctorInfo parameters:@{@"user_id":_userId} success:^(id  _Nonnull responseObject) {
        HEResponse *response = [HEResponse mj_objectWithKeyValues:responseObject];
        self.details = [HEDoctorInfoModel mj_objectWithKeyValues:response.data];

        [self initUI];
    } failure:^(NSError * _Nonnull error) {
 
    }];
}

- (void)initUI {
    
    _titleArr = @[@"擅长介绍", @"医疗教学背景介绍", @"个人成就", @"科室介绍"];
    _titleIcon = @[@"doctor_good_at", @"doctor_edu_bg", @"doctor_achieve", @"doctor_dept_desc"];

    [self.dataSourceArr addObject:[DYTools IsNotNull:_details.skilful]];
    [self.dataSourceArr addObject:[DYTools IsNotNull:_details.edu_bkg]];
    [self.dataSourceArr addObject:[DYTools IsNotNull:_details.achievement]];
    [self.dataSourceArr addObject:[DYTools IsNotNull:_details.depart_memo]];

    [self.view addSubview:self.tableView];
}


- (GDTableView *)tableView {
    if (!_tableView) {
        _tableView = [[GDTableView alloc] initWithFrame:CGRectMake(0, ZXNavBarHeight , KScreenWidth, KScreenHeight - ZXNavBarHeight) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.scrollsToTop = YES;
        _tableView.tableFooterView = [[UIView alloc] init];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.backgroundColor = KWhiteColor;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        [_tableView registerClass:[HEDoctorMainInfoCell class] forCellReuseIdentifier:@"HEDoctorMainInfoCell"];
        
        
        [_tableView registerClass:[HEDoctorMainSkuffCell class] forCellReuseIdentifier:@"HEDoctorMainSkuffCell"];
    }
    return _tableView;
}


#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        HEDoctorMainInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HEDoctorMainInfoCell"];
        cell.model = _details;
        return cell;
    }
    
    NSInteger row = indexPath.row - 1;
    HEDoctorMainSkuffCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HEDoctorMainSkuffCell"];
    cell.iconView.image = IMAGE_NAMED(_titleIcon[row]);
    cell.titleLb.text = _titleArr[row];
    cell.cotentLb.text = _dataSourceArr[row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellId = @"";
    if (indexPath.row == 0) {
        cellId = @"HEDoctorMainInfoCell";
        return [tableView fd_heightForCellWithIdentifier: cellId cacheByIndexPath:indexPath configuration:^(UITableViewCell *cell) {
        }];
    }else {
        NSInteger row = indexPath.row - 1;

        cellId = @"HEDoctorMainSkuffCell";
        return [tableView fd_heightForCellWithIdentifier: cellId cacheByIndexPath:indexPath configuration:^(HEDoctorMainSkuffCell *cell) {
            cell.iconView.image = IMAGE_NAMED(self.titleIcon[row]);
            cell.titleLb.text = self.titleArr[row];
            cell.cotentLb.text = self.dataSourceArr[row];
        }];
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}


@end
